package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.control.labels.LabelData;
import com.wgts.wgts.mvp.model.IJoinActionActivityModel;
import com.wgts.wgts.mvp.presenter.IJDGoodInfoActivityPersenter;
import com.wgts.wgts.mvp.presenter.IJoinActionActivityPresenter;
import com.wgts.wgts.mvp.view.IJoinActionActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.GuessingAndAwardOrderEntity;

import java.util.List;

public class JoinActionActivityPresenter implements IJoinActionActivityPresenter {

    private IJoinActionActivityModel model;

    private IJoinActionActivityView view;

    private Integer drawAllType;

    private Integer pageIndex = 1;

    private Integer pageSize = 20;

    private int pageSumSize = 0;

    public JoinActionActivityPresenter(IJoinActionActivityModel model, IJoinActionActivityView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void initJoinActivityList(Integer drawAllType) {
        this.pageIndex = 1;
        pageSumSize = 0;
        this.drawAllType = drawAllType;
        model.joinActivityList(drawAllType, this.pageIndex, this.pageSize, new HttpResultSubscriber<List<GuessingAndAwardOrderEntity>>() {
            @Override
            public void onSuccess(List<GuessingAndAwardOrderEntity> entities) {
                for (GuessingAndAwardOrderEntity  entity: entities){
                    pageSumSize += entity.list.size();
                }
                if(pageSumSize < pageSize){
                    view.initActionList(entities, true);
                }else{
                    view.initActionList(entities, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void loadMoreJoinActivityList() {
        pageSumSize = 0;
        model.joinActivityList(drawAllType, this.pageIndex, this.pageSize, new HttpResultSubscriber<List<GuessingAndAwardOrderEntity>>() {
            @Override
            public void onSuccess(List<GuessingAndAwardOrderEntity> entities) {
                for (GuessingAndAwardOrderEntity  entity: entities){
                    pageSumSize += entity.list.size();
                }
                if(pageSumSize < pageSize){
                    view.loadMoreActionList(entities, true);
                }else{
                    view.loadMoreActionList(entities, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
